package buybook;

import java.time.LocalDateTime;
import java.util.Random;
import java.util.Scanner;

public class BookStore {
    static Book[] books = new Book[6];

    static {
        books[0] = new Book(1, "java", 50, 20);
        books[1] = new Book(2, "c++", 40, 20);
        books[2] = new Book(3, "PHP", 30, 20);
        books[3] = new Book(4, "Python", 20, 20);
        books[4] = new Book(5, "web", 20, 20);
        books[5] = new Book(6, "mysql", 20, 20);
    }

    public static void main(String[] args) {
        showBook(books);
        Person p = new Person("张三");
        Book book = p.buyBook(books);
        showTotal(book, p);

    }

    public static void showBook(Book[] books) {
        System.out.println("图书编号\t图书名称\t图书价格\t库存");
        for (int i = 0; i < books.length; i++) {
            System.out.println(books[i].getId() + "\t" + books[i].getName() + "\t" + books[i].getPrice() + "\t" + books[i].getStorage());
        }
    }

    public static void showTotal(Book book, Person p) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入购书的数量");
        int number = sc.nextInt();
        double total = book.getPrice() * number;
        Random random = new Random();
        int orderNum = random.nextInt();
        System.out.println("订单编号:" + Math.abs(orderNum));
        System.out.println("购物时间" + LocalDateTime.now());
        System.out.println("会员:" + p.getName());
        System.out.println("图书名称" + book.getName() + ",单价" + book.getPrice() + "￥,购买数量" + number);
        System.out.println("-------------总计:" + book.getPrice() * number);
    }
}
